<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/MotaSiteStandard.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MotaWeb.Models.Announcement>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Site Announcements
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>

    <script type="text/javascript">
        function deleteRecord(recordId) {
            // Perform delete  
            var action = "/Announcement/Delete/" + recordId;

            var request = new Sys.Net.WebRequest();
            request.set_httpVerb("DELETE");
            request.set_url(action);
            request.add_completed(deleteCompleted);
            request.invoke();
        }

        function deleteCompleted() {
            // Reload page  
            window.location.reload();
        }  
    </script>

    <br />
    <table>
        <tr>
            <th>
            </th>
            <th>
                Message
            </th>
            <th>
                EffectiveDate
            </th>
            <th>
                ExpirationDate
            </th>
            <th />
        </tr>
        <% foreach (var item in Model)
           { %>
        <tr>
            <td>
                <%= Html.ActionLink("Edit", "Edit", new { id=item.Id }) %>
                |
                <%= Html.ActionLink("Details", "Details", new { id=item.Id})%>
            </td>
            <td>
                <%= Html.Encode(item.Message) %>
            </td>
            <td>
                <%= Html.Encode(String.Format("{0:g}", item.EffectiveDate)) %>
            </td>
            <td>
                <%= Html.Encode(String.Format("{0:g}", item.ExpirationDate)) %>
            </td>
            <td>
                <%-- Ajax Delete --%>  
                <a onclick="deleteRecord(<%= item.Id %>)" href="JavaScript:void(0)">Delete</a>  
            </td>
        </tr>
        <% } %>
    </table>
    <p>
        <%= Html.ActionLink("Create New", "Create") %>
    </p>
</asp:Content>
